﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Text;
using System.Windows.Forms;

namespace PlanningGIS.MetadataEdit
{
    public partial class FrmSelectField : Form
    {
        public FrmSelectField()
        {
            InitializeComponent();
        }
        private List<string> fields;
        private List<string> selectedFields=new List<string>();
        public List<string> SelectedFields
        {
            get{
                return selectedFields;
            }            

        }
        public List<string> Fields
        {
            set
            {
                fields = value;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {          
            Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            selectedFields.Clear();
            foreach (ListViewItem  item in listView1.CheckedItems)
            {
                selectedFields.Add(item.Text);
            }
            DialogResult = DialogResult.OK;
            Close();
        }

        private void FrmSelectField_Load(object sender, EventArgs e)
        {
            if (fields != null)
            {
                listView1.Items.Clear();
                foreach (string str in fields)
                {
                    listView1.Items.Add(str);
                }
            }
        }

        private void mnuSelectAll_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                listView1.Items[i].Checked = true;
            }
            
        }

        private void mnuUnSelectAll_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                listView1.Items[i].Checked = false;
            }
        }

        private void 选中项勾选ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.SelectedItems.Count; i++)
            {
                listView1.SelectedItems[i].Checked = true ;
            }
        }

        private void 选中项取消勾选ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listView1.SelectedItems.Count; i++)
            {
                listView1.SelectedItems[i].Checked = false;
            }
        }

    }
}
